package com.ngc.mall.controller;

import com.ngc.mall.common.configure.response.ResponseResult;
import com.ngc.mall.domain.OrderDomain;
import com.ngc.mall.dto.DeliveryDTO;
import com.ngc.mall.dto.OrderFilterDTO;
import com.ngc.mall.service.IOrderService;
import com.ngc.mall.vo.PagingVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 
 * 
 * @author: chenxiaolin 
 * @date 2023/7/13 15:46
**/
@RestController
@RequestMapping("/order")
@Api(tags = "订单")
public class OrderController {
    @Resource
    private IOrderService iOrderService;

    /**
     * 获取订单列表
     * @return
     */
    @PostMapping("/search")
    @ApiOperation("获取订单列表")
    public ResponseResult<PagingVO> selectAllOrder(@RequestBody OrderFilterDTO dto,
                                                   @RequestParam(name = "start", defaultValue = "0")
                                                                    Integer start,
                                                   @RequestParam(name = "count", defaultValue = "8")
                                                                        Integer count){
        return ResponseResult.success(iOrderService.search(dto,start,count));
    }


    @GetMapping("/all/by_memberId/{id}")
    @ApiOperation("根据id查看会员消费记录")
    public ResponseResult<List<OrderDomain>> findAllOrderByMemberId(@PathVariable Long id){
        return ResponseResult.success(iOrderService.getOrderByMemberId(id));
    }


    /**
     * 根据id查看订单详情
     * @param id
     * @return
     */
    @GetMapping("/id/{id}")
    @ApiOperation(value = "根据id查看订单详情")
    public ResponseResult<OrderDomain> getDetailById(@PathVariable Long id){
        return ResponseResult.success(
                iOrderService.getOrderDetailById(id)
        );
    }


    @PutMapping("/status/delivered/{id}")
    @ApiOperation(value="确定发货")
    public ResponseResult<Boolean> updateStatusToShipped(@PathVariable Long id, @RequestBody DeliveryDTO deliveryDTO){
        return ResponseResult.success(iOrderService.updateStatusToDelivered(id,deliveryDTO));
    }


    @DeleteMapping("/{id}")
    @ApiOperation("删除订单")
    public ResponseResult<Boolean> deleteOrderById(@PathVariable Long id){
        return ResponseResult.auto(iOrderService.removeById(id));
    }


}
